home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / Raven 1.2 Examples.sit / Raven 1.2 Examples / Quill / Source / WindowSizeEditor.cpp < prev    next >
Text File  |  1997-08-08  |  5KB  |  191 lines

  1. /*
  2.  *  File:       WindowSizeEditor.h
  3.  *  Summary:       A view that knows how to edit a TWindow's size info.
  4.  *  Written by: Jesse Jones
  5.  *
  6.  *  Copyright ゥ 1996 Jesse Jones. 
  7.  *    For conditions of distribution and use, see copyright notice in ZTypes.h  
  8.  *
  9.  *  Change History (most recent first):    
  10.  *
  11.  *         <->    12/24/96    JDJ        Created
  12.  */
  13.  
  14. #include "WindowSizeEditor.h"
  15.  
  16. #include <ZDialogUtils.h>
  17. #include <ZTextBox.h>
  18.  
  19.  
  20. // ===================================================================================
  21. //    class CEditWindowSizeCommand
  22. // ===================================================================================
  23.  
  24. //---------------------------------------------------------------
  25. //
  26. // CEditWindowSizeCommand::~CEditWindowSizeCommand
  27. //
  28. //---------------------------------------------------------------
  29. CEditWindowSizeCommand::~CEditWindowSizeCommand()
  30. {
  31. }
  32.  
  33.  
  34. //---------------------------------------------------------------
  35. //
  36. // CEditWindowSizeCommand::CEditWindowSizeCommand
  37. //
  38. //---------------------------------------------------------------
  39. CEditWindowSizeCommand::CEditWindowSizeCommand(TWindow* pane, const SWindowInfo& oldInfo, const SWindowInfo& newInfo) : Inherited(pane, oldInfo, newInfo)
  40. {
  41. }
  42.  
  43.  
  44. //---------------------------------------------------------------
  45. //
  46. // CEditWindowSizeCommand::UpdatePane
  47. //
  48. //---------------------------------------------------------------
  49. void CEditWindowSizeCommand::UpdatePane(const SWindowInfo& newInfo)
  50. {
  51.     SWindowInfo info = mPane->GetInfo();
  52.     
  53.     info.attr.minSize = newInfo.attr.minSize;
  54.     info.attr.maxSize = newInfo.attr.maxSize;
  55.  
  56.     mPane->SetInfo(info);
  57. }
  58.  
  59. #pragma mark -
  60.  
  61. // ===================================================================================
  62. //    CWindowSizeEditor
  63. // ===================================================================================
  64.  
  65. static TReanimatorRegister<CWindowSizeEditor> sWindowSizeEditorRegistrar;
  66.  
  67. //---------------------------------------------------------------
  68. //
  69. // CWindowSizeEditor::~CWindowSizeEditor
  70. //
  71. //---------------------------------------------------------------
  72. CWindowSizeEditor::~CWindowSizeEditor()
  73. {
  74. }
  75.  
  76.  
  77. //---------------------------------------------------------------
  78. //
  79. // CWindowSizeEditor::CWindowSizeEditor
  80. //
  81. //---------------------------------------------------------------
  82. CWindowSizeEditor::CWindowSizeEditor(TView* superView) : Inherited(superView)
  83. {
  84. }
  85.  
  86.  
  87. //---------------------------------------------------------------
  88. //
  89. // CWindowSizeEditor::Create                            [static]
  90. //
  91. //---------------------------------------------------------------
  92. MReanimatable* CWindowSizeEditor::Create(MReanimatable* parent)
  93. {
  94.     return new CWindowSizeEditor(dynamic_cast<TView*>(parent));
  95. }
  96.  
  97.  
  98. //---------------------------------------------------------------
  99. //
  100. // CWindowSizeEditor::Validate
  101. //
  102. //---------------------------------------------------------------
  103. bool CWindowSizeEditor::Validate()
  104. {
  105.     bool valid = Inherited::Validate();
  106.     
  107.     if (valid) {
  108.         TTextBox* textBox = nil;
  109.         TSize minSize, maxSize;
  110.             
  111.         textBox = dynamic_cast<TTextBox*>(this->FindSubPane("MinSizeH"));
  112.         minSize.width = textBox->GetValue();
  113.         
  114.         textBox = dynamic_cast<TTextBox*>(this->FindSubPane("MinSizeV"));
  115.         minSize.height = textBox->GetValue();
  116.         
  117.         textBox = dynamic_cast<TTextBox*>(this->FindSubPane("MaxSizeH"));
  118.         maxSize.width = textBox->GetValue();
  119.         
  120.         textBox = dynamic_cast<TTextBox*>(this->FindSubPane("MaxSizeV"));
  121.         maxSize.height = textBox->GetValue();
  122.         
  123.         if (minSize.width > maxSize.width) {
  124.             DoStop(LoadAppString("Min width is greater than max width!"), "");
  125.             dynamic_cast<TTextBox*>(this->FindSubPane("MinSizeH"))->SelectAll();
  126.             
  127.             valid = false;
  128.             
  129.         } else if (minSize.height > maxSize.height) {
  130.             DoStop(LoadAppString("Min width is greater than max height!"), "");
  131.             dynamic_cast<TTextBox*>(this->FindSubPane("MinSizeV"))->SelectAll();
  132.             
  133.             valid = false;
  134.         }
  135.     }
  136.     
  137.     return valid;
  138. }
  139.  
  140.  
  141. //---------------------------------------------------------------
  142. //
  143. // CWindowSizeEditor::GetEditorInfo        
  144. //
  145. //---------------------------------------------------------------
  146. SWindowInfo CWindowSizeEditor::GetEditorInfo() const
  147. {
  148.     SWindowInfo info;
  149.     
  150.     TTextBox* textBox = nil;
  151.         
  152.     textBox = dynamic_cast<TTextBox*>(this->FindSubPane("MinSizeH"));
  153.     info.attr.minSize.width = textBox->GetValue();
  154.     
  155.     textBox = dynamic_cast<TTextBox*>(this->FindSubPane("MinSizeV"));
  156.     info.attr.minSize.height = textBox->GetValue();
  157.     
  158.     textBox = dynamic_cast<TTextBox*>(this->FindSubPane("MaxSizeH"));
  159.     info.attr.maxSize.width = textBox->GetValue();
  160.     
  161.     textBox = dynamic_cast<TTextBox*>(this->FindSubPane("MaxSizeV"));
  162.     info.attr.maxSize.height = textBox->GetValue();
  163.     
  164.     return info;
  165. }
  166.  
  167.  
  168. //---------------------------------------------------------------
  169. //
  170. // CWindowSizeEditor::SetEditorInfo
  171. //
  172. //---------------------------------------------------------------
  173. void CWindowSizeEditor::SetEditorInfo(const SWindowInfo& info)
  174. {
  175.     TTextBox* textBox = nil;
  176.         
  177.     textBox = dynamic_cast<TTextBox*>(this->FindSubPane("MinSizeH"));
  178.     textBox->SetValue(info.attr.minSize.width);
  179.     
  180.     textBox = dynamic_cast<TTextBox*>(this->FindSubPane("MinSizeV"));
  181.     textBox->SetValue(info.attr.minSize.height);
  182.     
  183.     textBox = dynamic_cast<TTextBox*>(this->FindSubPane("MaxSizeH"));
  184.     textBox->SetValue(info.attr.maxSize.width);
  185.     
  186.     textBox = dynamic_cast<TTextBox*>(this->FindSubPane("MaxSizeV"));
  187.     textBox->SetValue(info.attr.maxSize.height);
  188. }
  189.  
  190.  
  191.